// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.designer.core.data;

import java.util.ArrayList;
import java.util.List;

import org.dengues.core.process.EConnectionType;
import org.dengues.core.process.ICompConnection;
import org.dengues.core.process.ICompNode;
import org.dengues.core.process.ICompSubProcess;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public class CompSubProcess implements ICompSubProcess {

    private final List<ICompNode> compNodes;

    private final ICompNode rootNode;

    private List<String> beforeProcess;

    /**
     * Qiang.Zhang.Adolf@gmail.com CompSubProcess constructor comment.
     * 
     * @param rootNode
     */
    public CompSubProcess(ICompNode rootNode) {
        this.rootNode = rootNode;
        this.compNodes = new ArrayList<ICompNode>();
        beforeProcess = new ArrayList<String>();
        buildSubProcess(rootNode);
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "buildSubProcess".
     * 
     * @param compNode
     */
    private void buildSubProcess(ICompNode compNode) {
        for (ICompConnection conn : compNode.getOutgoingConnections()) {
            ICompNode target = (ICompNode) conn.getTarget();
            if (target != null) {
                if (EConnectionType.MAIN.equals(conn.getType())) {
                    buildSubProcess(target);
                    beforeProcess.addAll(compNode.getDataUniques());
                } else if (EConnectionType.DATA.equals(conn.getType())) {
                    // beforeProcess.add(conn.getTarget().getUniqueName());
                }

            }
        }
        compNodes.add(compNode);
    }

    /**
     * Getter for compNodes.
     * 
     * @return the compNodes
     */
    public List<? extends ICompNode> getCompNodes() {
        return this.compNodes;
    }

    /**
     * Getter for rootNode.
     * 
     * @return the rootNode
     */
    public ICompNode getRootNode() {
        return this.rootNode;
    }

    /**
     * Getter for beforeProcess.
     * 
     * @return the beforeProcess
     */
    public List<String> getBeforeProcess() {
        return this.beforeProcess;
    }

}
